package karaoke.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import karaoke.excepcion.DAOExcepcion;
import karaoke.negocio.GestionLocal;
import karaoke.negocio.GestionReserva;
import karaoke.negocio.GestionSala;

/**
 * Servlet implementation class SalaInsertarServlet
 */
@WebServlet("/SalaInsertarServlet")
public class SalaInsertarServlet extends HttpServlet {
	
	  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
	            throws ServletException, IOException {
	        response.setContentType("text/html;charset=UTF-8");
	        PrintWriter out = response.getWriter();
	        try {
	            GestionSala gestionSala = new GestionSala();
	            String capacidad = request.getParameter("capacidad");
	            String nombre = request.getParameter("nombre");
	            String descripcion = request.getParameter("descripcion");
	            int idlocal       = Integer.parseInt(request.getParameter("selLocal"));
	            String estado = request.getParameter("estado");
	 
	            gestionSala.insertar(nombre, capacidad, descripcion, estado);
	            
	            response.sendRedirect(request.getContextPath() + "/SalaBuscarServlet");
	        } catch (DAOExcepcion e) {
	            System.out.println(e.getMessage());
	            RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
	            rd.forward(request, response);
	        } finally {
	            out.close();
	        }
	    }
	    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */

	
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SalaInsertarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
    
    

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		processRequest(request, response);
	}

	
}
